#define _CRT_SECURE_NO_WARNINGS 1
//#include <iostream>
//#include <algorithm>
//using namespace std;
//const int N = 310;
//typedef long long LL;
//int h[N], a[N];
//LL ret;
//int n;
//int main()
//{
//	cin >> n;
//	for (int i = 1; i <= n; i++)
//	{
//		cin >> h[i];
//	}
//	sort(h + 1, h + n + 1);
//	for (int i = 1; i <= n; i++)
//	{
//		if (i % 2 == 0)
//		{
//			a[i] = h[i / 2];
//		}
//		else
//		{
//			a[i] = h[n - (i - 1 / 2)];
//		}
//		cout << a[i] << endl;
//	}
//	for (int i = 1; i <= n; i++)
//	{
//		ret += (a[i] - a[i - 1]) * (a[i] - a[i - 1]);
//	}
//	cout << ret << endl;
//}

#include <iostream>
using namespace std;
const int N = 1e5 + 10;
typedef long long LL;
LL sum[N];
int n, m;
bool check(LL x)
{
	int cnt = 1;
	for (int left = 1, right = 1; right <= n; right++)
	{
		if (sum[right] - sum[left - 1] > x)
		{
			cnt++;
			left = right;
		}
	}
	return cnt <= m;
}
int main()
{
	cin >> n >> m;
	LL left, right;
	for (int i = 1; i <= n; i++)
	{
		LL x;
		cin >> x;
		left = max(left, x);
		sum[i] = sum[i - 1] + x;
		right = max(right, sum[i]);
	}
	
	while (left < right)
	{
		LL mid = (left + right) / 2;
		if (check(mid))
		{
			right = mid;
		}
		else
		{
			left = mid + 1;
		}
	}
	cout << left << endl;
	return 0;
}
